package com.example.keyon;

import org.python.core.PyFunction;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @Author Keyon
 * @Date 2020/4/5 21:52
 * @Desc 树莓派摄像头
 */
public class PiCamera {

    /**
     * 调用树莓派摄像头
     * 生成图片名：QRCODE.png
     */
    public static void takePicture() {
        execPythonFunction("camera.py");
    }

    private static void execPythonFunction(String fileName) {
        try{
            Process pr = Runtime.getRuntime().exec("python " + fileName);

            BufferedReader in = new BufferedReader(new
                    InputStreamReader(pr.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            pr.waitFor();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

}
